package day11.exc;

import java.util.concurrent.*;

/**
 * <>
 * <详细描述>
 *
 * @Author WANG.SONG.
 * @Date 2019/3/15 0015 22:53
 * @see
 */
public class Executor {
    static ThreadPoolExecutor exe = new ThreadPoolExecutor(2,3,10L, TimeUnit.SECONDS,new LinkedBlockingDeque());
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ServiceA a= new ServiceA();
        ServiceB b =new ServiceB();
        exe.execute(new Runnable() {
            @Override
            public void run() {

//                a.say();
            }
        });
        exe.execute(new Runnable() {
            @Override
            public void run() {
               // a.say();
//                b.say();
            }
        });

        Callable <Object> callable = new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                return "hello";
            }
        };
        Future<Object> future = exe.<Object>submit(callable);
        try {

            Object object =future.get();
            future.cancel(false);
            System.out.println(object);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("do task");
            }
        };
        Object object="aaaaaaaaaaaaaaaaaaaaaaa";
        Future<Object> future2 = exe.<Object>submit(runnable,object);
        System.out.println(future2.get());

    }

}
